<template>
	<view class="index">
		<view class="search-wrapper">
			<input confirm-type="search" @confirm="downCallback" type="text" v-model="keywords" class="input"
				placeholder="输入装车工名称查询" />
			<uni-icons v-if="keywords" type="clear" @tap="keywords = ''" size="18" color="#898989"
				class="close"></uni-icons>
			<image src="../static/image/search-icon.png" class="icon" mode="widthFix"></image>
			<view class="search-btn" @click="downCallback">
				搜索
			</view>
		</view>
		<mescroll-uni ref="mescrollRef" height="100%" @init="mescrollInit" bottom="180" :down="downOption"
			@down="downCallback" :up="upOption" @up="upCallback">
			<!-- 数据列表 -->
			<view class="item" v-for="(item,index) in list" :key="index" @click="goDetail(item)">
				<view class="vehicle-wrapper">
					<view class="vehicle-info">
						<text class="licensePlateNo">{{ item.loaderName }}</text>
						<text v-if="item.loaderStatus === 1" class="status">已启用</text>
						<text v-else class="status disabled">已禁用</text>
					</view>
				</view>
				<view class="info">
					<text @click.stop="callPhone(item.loaderTel)">联系电话：{{ item.loaderTel || '-' }}</text>
				</view>
				<view class="info">
					<text>身份证号：{{ item.identityCardNo || '-' }}</text>
				</view>
			</view>
		</mescroll-uni>
		<view v-if="$permissions.verify('app:loader:operate')" class="btn-wrapper" @click="add">
			<view class="btn">
				新增装车工
			</view>
		</view>
	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import MescrollMoreItemMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mixins/mescroll-more-item.js";
	export default {
		mixins: [MescrollMixin, MescrollMoreItemMixin], // 注意此处还需使用MescrollMoreItemMixin (必须写在MescrollMixin后面)
		data() {
			return {
				downOption: {
					auto: true // 不自动加载 (mixin已处理第一个tab触发downCallback)
				},
				upOption: {
					auto: false, // 不自动加载
					textNoMore: '没有更多啦~',
					noMoreSize: 3, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
					empty: {
						fixed: true,
						top: '200upx',
						tip: '~ 空空如也 ~', // 提示
						icon: 'https://sm.hobon.cc/static/hobon_noorder.png'
					}
				},
				isLoading: true,
				list: [],
				pageNum: 1,
				pageSize: 10,
				keywords: '',

			}
		},
		onLoad(option) {

		},
		methods: {
			/*下拉刷新的回调 */
			downCallback() {
				// 这里加载你想下拉刷新的数据, 比如刷新轮播数据
				// loadSwiper();
				// 下拉刷新的回调,默认重置上拉加载列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
				this.mescroll.resetUpScroll()
			},
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			async upCallback(page) {
				//let status = ['1', '2', '10', '11', '3']
				this.pageNum = page.num;
				const params = {
					pageNum: this.pageNum,
					pageSize: this.pageSize,
					loaderName: this.keywords,
					orders: [{
						"asc": false,
						"column": "id"
					}],
				};
				const data = await this.$api.post('/adm/loaderinfo/page', params, false)
				if (data.code === 200) {
					this.isLoading = false;
					if (this.pageNum === 1) {
						this.list = [];
					}
					this.list = this.list.concat(data.data.records);
					this.mescroll.endBySize(data.data.records.length, data.data.total);
				} else {
					this.mescroll.endErr();
				}
			},
			callPhone(tel) {
				if (!tel) return
				uni.makePhoneCall({
					phoneNumber: tel
				})
			},
			goDetail(item) {
				uni.navigateTo({
					url: "/subPage_loader/newLoader?id=" + item.id
				})
			},
			add() {
				uni.navigateTo({
					url: '/subPage_loader/newLoader'
				})
			}
		},
		components: {

		}
	}
</script>

<style lang="scss" scoped>
	.index {
		height: 100%;
		overflow: hidden;

		.search-wrapper {
			background-color: #ffffff;
			margin: 3upx 0;
			padding: 10upx 20upx;
			position: relative;
			display: flex;
			align-items: center;

			.input {
				border-radius: 10upx;
				border: 2upx solid #acacac;
				height: 70upx;
				width: 100%;
				padding: 0 120upx 0 30upx;
				box-sizing: border-box;
				font-size: 32upx;
			}

			.icon {
				position: absolute;
				top: 50%;
				transform: translateY(-50%);
				right: 180upx;
				width: 26upx;
				height: 26upx;
			}

			.close {
				position: absolute;
				top: 50%;
				transform: translateY(-50%);
				right: 230upx;
			}

			.search-btn {
				width: 150upx;
				background-color: #555BFF;
				color: #ffffff;
				height: 70upx;
				display: flex;
				align-items: center;
				justify-content: center;
				border-radius: 10upx;
				margin-left: 10upx;
				font-size: 28upx;

				&.scan {
					width: 250upx;
				}
			}
		}

		.item {
			margin: 20upx;
			border-radius: 20upx;
			background-color: #ffffff;
			overflow: hidden;
			padding-bottom: 30rpx;

			.vehicle-wrapper {
				background-color: #F5F6FA;
				padding: 14rpx 30rpx;

				.vehicle-info {
					display: flex;
					align-items: center;
					justify-content: space-between;

					.licensePlateNo {
						font-size: 32rpx;
						font-weight: bold;
					}

					.status {
						color: #009800;
						font-size: 32rpx;

						&.disabled {
							color: #f00
						}
					}
				}

				.vehicleModel {
					font-size: 28rpx;
					color: #666666;
				}
			}

			.info {
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-top: 20rpx;
				padding: 0 30rpx;
			}
		}

		.btn-wrapper {
			position: fixed;
			height: 100upx;
			width: 100%;
			left: 0;
			bottom: 0;
			background-color: #ffffff;
			display: flex;
			align-items: center;
			z-index: 1;
			box-sizing: border-box;

			.btn {
				display: flex;
				align-items: center;
				justify-content: center;
				flex: 1;
				height: 100%;
				background-color: #555BFF;
				color: #ffffff;

				&.default {
					color: #232323;
					background-color: #ffffff;
				}
			}
		}
	}
</style>